<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
	<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <script src="bootstrap/jquery/jquery-3.4.1.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
	<jsp:include page="header.jsp"></jsp:include>
	<div class="wrap">
	<div class="main">
		<div class="content">
			<div class="content_top">
				<div class="heading">
					<h3>回收产品</h3>
				</div>
				<!-- <div class="sort">
					<p>
						Sort by: <select>
							<option>Lowest Price</option>
							<option>Highest Price</option>
							<option>Lowest Price</option>
							<option>Lowest Price</option>
							<option>Lowest Price</option>
							<option>In Stock</option>
						</select>
					</p>
				</div>
				<div class="show">
					<p>
						Show: <select>
							<option>4</option>
							<option>8</option>
							<option>12</option>
							<option>16</option>
							<option>20</option>
							<option>In Stock</option>
						</select>
					</p>
				</div> -->
				<div class="page-no">
					${pageTool}
					
					<!-- 
					<p>结果页:
					<ul>
						<li><a href="#">首页</a></li>
						<li><a href="#">上一页</a></li>
						<li><a href="#">当前页</a></li>
						<li><a href="#">下一页</a></li>
						<li><a href="#">尾页</a></li>
					</ul>
					</p> -->
				</div>
				<div class="clearfix"></div>
			</div>
			<div class="section group" style="min-height:384px">
				<c:forEach items="${products}" var="pro">
				<div class="grid_1_of_4 images_1_of_4">
					<img src="${pro.pimage}" alt="" />
					<h2>${pro.pname}</h2>
					<p>${pro.pdesc}</p>
					<p><span class="price">${pro.pprice}元/kg</span></p>
					<div class="button images_button" >
						<span>
							<img src="images/cart.jpg" alt="" />
							<input type="hidden" value="${pro.pimage}" name="pimage">
							<input type="hidden" value="${pro.pid}" name="pid">
				            <input type="hidden" value="${pro.pname}" name="pname">
				            <input type="hidden" value="${pro.pprice}" name="pprice">
				            <input type="hidden" value="1.00" name="weight">
				            <c:if test="${user.uid==null}">
				            	<input type="hidden" value="0" name="uid"> 
				            </c:if>
				             <c:if test="${user.uid!=null}">
				            	<input type="hidden" value="${user.uid}" name="uid">  
				            </c:if>
				            <input type="hidden" value="add_ajax" name="action">
							<button class="cart-button btn-addtocart" id="">加入出售页</button>
						</span>
					</div>
				</div>
				</c:forEach>
				<div class="clearfix"></div>
			</div>
		</div>
		</div>
	</div>
	<jsp:include page="bottom.jsp"></jsp:include>
	<script type="text/javascript">
		$(function() {
			$(".btn-addtocart").click(function() {
				//alert($(this).prev().prev().val());
				var uid =$(this).prev().prev().val();
				if(uid==0||uid==null||uid==" "){
					alert("请登录后再进行该操作！");
					return;
				}
				//alert($(this).prev().val());
				//获取参数
			 	/* var e=$(this);
				while(e.prev().val()!=null){
					e=e.prev();
					alert(e.val());
				} */
				
				$.ajax({
					url : "cart",
					type : "post",
					data : {
						"action":$(this).prev().val(),
						"uid":$(this).prev().prev().val(),
						"weight":$(this).prev().prev().prev().val(),
						"pprice":$(this).prev().prev().prev().prev().val(),
						"pname" :$(this).prev().prev().prev().prev().prev().val(),
						"pid" : $(this).prev().prev().prev().prev().prev().prev().val(),
						"pimage" : $(this).prev().prev().prev().prev().prev().prev().prev().val(),
					},
					dataType : "text",
					success : function(result) {
						if (result == '1') {
							alert("操作成功！");
						} else {
							alert("操作失败！");
						}
					},
					error : function() {
						alert("系统发生错误，请联系管理员！");
					}
				})

			})
		})
	</script>
</body>
</html>